<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFoodClassificationTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('food_classification_first', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->comment('食品分类名称');
            $table->integer('sort')->comment('排序');
            $table->timestamps();
        });
        Schema::create('food_classification_second', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->comment('食品分类名称');
            $table->integer('sort')->comment('排序');
            $table->unsignedBigInteger('pid')->comment('一级id')->nullable();
            $table->foreign('pid')->references('id')->on('food_classification_first')->onDelete('NO ACTION');
            $table->timestamps();
        });
        Schema::create('food_classification_third', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->comment('食品分类名称');
            $table->integer('sort')->comment('排序');
            $table->unsignedBigInteger('pid')->comment('二级id')->nullable();
            $table->foreign('pid')->references('id')->on('food_classification_second')->onDelete('NO ACTION');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('food_classification_third');
        Schema::dropIfExists('food_classification_second');
        Schema::dropIfExists('food_classification_first');
    }
}
